home *** CD-ROM | disk | FTP | other *** search
- (******************************************************************************
- * rtObj *
- * please notice - *
- * this unit includes both the object3d unit, and the superobj unit, *
- * and it is used with no reference to the WWToolKit window GUI library, *
- * uses project3, instead of prjWind (It does, however, support OWL) *
- * *
- * In V2.x - The support collections are part of this unit as well ... *
- * V3.x adds os/2 support *
- ******************************************************************************)
- Unit rtObj;
- {$ifdef os2}
- {$X+}
- {$endif}
-
- (*******************************************************************************
- * 3D Objects *
- * ---------- *
- * *
- * A 3D object is a collection of points and lines in the 3D universe, *
- * that represent the body we want to draw on the screen. *
- * A 3D object is allways centered around point (0, 0, 0) in the 3D universe. *
- * (Its center of gravity assuming it is has a uniform weight distribution *
- * is in point (0, 0, 0) *
- * At any moment during the object's life, we know it's distance from the *
- * origin, And it's rotation using reveres rotation CTM. *
- * *
- * 3D Object methods: *
- * constructor Open *
- * destructor CloseMe *
- * procedures: Rotate, Scale, Move, Show, Hide, Load, Save *
- * SetToOrigin, Paint *
- * *
- *******************************************************************************)
-
- interface
-
- uses
- {$ifdef windows}
- winTypes
- ,winProcs
- {$else}
- {$ifdef os2}
- os23dsup
- {$else}
- graph
- {$endif}
- {$endif}
- ,Ctm3d
- ,hdr3d
- ,project3
- ,objects { needed for collection support .. }
- ;
-
- type
- P3dPointCollection = ^ T3dPointCollection;
- T3dPointCollection = object(TCollection)
-
- procedure freeItem(item : pointer); virtual;
-
- end; { T3dPointCollection definition .. }
-
- P3dLineCollection = ^ T3dLineCollection;
- T3dLineCollection = object(TCollection)
-
- procedure freeItem(item : pointer); virtual;
-
- end; { T3dLineCollection definition .. }
-
- PScreenPointsCollection = ^ TScreenPointsCollection;
- TScreenPointsCollection = object(TCollection)
-
- procedure freeItem(item : pointer); virtual;
-
- end; { TScreenPointsCollection definition .. }
-
- type
- {$ifdef os2}
- f_real = file;
- {$else}
- f_real = file of real;
- {$endif}
-
- {===================================================================}
- { Base object is the base class for 3D-objects. some functions }
- { are dummy virtual do-nothing, which are are implemented only for }
- { the descendend objects derived from BaseObject }
- {===================================================================}
-
- BaseObjectPtr = ^BaseObject;
- BaseObject = object
- MyCtm : Ctm; { This CTM applied to the object gives the }
- { objects Position after transformations }
- Name : String; { Identifies the object }
- myColor : word; { Main color for the object }
- Location : point3d; { Central of gravity in real space }
- scrPntUpdt : boolean; { True if screen points updated }
-
- constructor open(myName : string; color : word);
- destructor CloseMe; virtual;
- {$ifdef windows}
- procedure show(dc : hdc); virtual;
- procedure hide(dc : hdc); virtual;
- procedure paint(dc : hdc); virtual; {in specified color}
- {$else}
- {$ifdef os2}
- procedure show(ps : hps); virtual;
- procedure hide(ps : hps); virtual;
- procedure paint(ps : hps); virtual; {in specified color}
- {$else}
- procedure show; virtual;
- procedure hide; virtual;
- procedure paint; virtual; {in specified color}
- {$endif}
- {$endif}
- procedure updateScreenPoints; virtual; {transform object 3D -> 2D}
- procedure move(axis : axisType; by : real); virtual;
- procedure translate(dx, dy, dz : integer); virtual;
- {multy dimentional move in 1 call}
- procedure scale(axis : axisType; factor : real); virtual;
- procedure allScale(sx, sy, sz : real); virtual;
- {multy dimentional scale in 1 call}
- procedure rotate(axis : axisType; deg : real); virtual;
-
- procedure goto3dPos(x, y, z : real); virtual; {translate to absolute place}
- procedure setToOrigin; virtual;
- {translate to 0,0,0, update points, and set myCtm to unit}
- procedure calcLocation; virtual; {set Location to central gravity}
- procedure deleteTransform; virtual; {set MyCtm to unit}
-
- function load : word; virtual; {from disk}
- function save : word; virtual; {to disk}
- procedure writeMe(var elementFile : f_real); virtual; {to disk .. without opening file..}
- procedure readMe(var elementFile : f_real); virtual;
- end;
-
- {===================================================================}
- { Obj3d is an object which represents a 3-D object with a poligon }
- { mesh. }
- {===================================================================}
-
- Obj3dPtr = ^Obj3d;
- Obj3d = object(BaseObject)
- (* Points : array[1..MaxPoints] of point3d; *)
- Points : T3dPointCollection;
- (* Lines : array[1..MaxLines] of Line3d; *)
- Lines : T3dLineCollection;
- (* scrPoints : array[1..MaxPoints] of screenPoints; *)
- scrPoints : TScreenPointsCollection;
- NumOfLines : integer;
- NumOfPoints : integer;
- ReverseRot : Ctm; { Saves only the reverse rotations }
- unReverseRot: Ctm; { reverse of the above}
-
- constructor open(myName : string; ref : point3d; color : word);
- destructor CloseMe; virtual;
- {$ifdef windows}
- procedure paint(dc : hdc); virtual; {in specified color}
- {$else}
- {$ifdef os2}
- procedure paint(ps : hps); virtual; {in specified color}
- {$else}
- procedure paint; virtual; {in specified color}
- {$endif}
- {$endif}
- procedure updateScreenPoints; virtual; {transform object 3D -> 2D}
-
- procedure calcLocation; virtual; {set Location to central gravity}
- procedure setToOrigin; virtual;
-
- procedure writeMe(var elementFile : f_real); virtual;
- procedure readMe(var elementFile : f_real); virtual;
- end;
-
- const
- maxSubObjects = 15;
-
- type
- complexObjPtr = ^complexObj;
- ComplexObj = object(BaseObject)
- childs : array [1..maxSubObjects] of obj3dPtr;
- ctms : array [1..maxSubObjects] of ctm;
- numOfChilds : integer; {counter of # of obj3d childs}
-
- constructor open(myName : string; color : word);
- destructor closeMe; virtual;
- procedure updateScreenPoints; virtual;
- procedure writeMe(var elementFile : f_real); virtual;
- procedure readMe(var elementFile : f_real); virtual;
- procedure calcLocation; virtual;
- {$ifdef WINDOWS}
- procedure paint(dc : hdc); virtual;
- {$else}
- {$ifdef os2}
- procedure paint(ps : hps); virtual;
- {$else}
- procedure paint; virtual;
- {$endif}
- {$endif}
- procedure move(axis : axisType; by : real); virtual;
- procedure rotate(axis : axisType; deg : real); virtual;
- procedure scale(axis : axisType; factor : real); virtual;
-
- function addSubObject(myName : string; refPoint : point3d) : word;
- function getChildPtr(index : integer) : obj3dPtr;
- procedure rotateChild(child : integer; axis : axisType;
- deg : real);
- procedure scaleChild(child : integer; axis : axisType;
- factor : real);
- procedure moveChild(child : integer; axis : axisType;
- by : real);
- end;
-
-
- implementation
- end.
-